package com.xuecheng.content.controller;

import com.xuecheng.api.contant.model.dto.CourseTeacherDTO;
import com.xuecheng.api.contant.model.vo.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.entity.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    /**
     *  删除课程教师信息
     * @param courseBaseId 课程基本信息id
     * @param teacherId 教师id
     */
    @DeleteMapping("/courseTeacher/course/{courseId}/{teacherId}")
    public void removeCourseTeacher(@PathVariable("courseId") Long courseBaseId, @PathVariable("teacherId") Long teacherId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.removeCourseTeacher(courseBaseId,teacherId,companyId);
    }


    /**
     * 添加课程教师基本信息
     * @param courseTeacherVO 前端传过来的VO实体类数据
     * @return 返回DTO数据给前端
     */
    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyCourseTeacher(@RequestBody CourseTeacherVO courseTeacherVO) {
        Long companyId = SecurityUtil.getCompanyId();
        // 1、vo转dto
        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.vo2dto(courseTeacherVO);
        // 2、调用方法
        CourseTeacherDTO dto = courseTeacherService.createOrModifyCourseTeacher(courseTeacherDTO,companyId);
        // 3、返回数据
        return dto;
    }


    /**
     * 根据课程信息id查询课程教师信息
     * @param id 课程教师信息id
     * @return 返回数据
     */
    @GetMapping("courseTeacher/list/{id}")
    public List getCourseTeacher(@PathVariable Long id){;
        Long companyId = SecurityUtil.getCompanyId();
        // 1.调用方法
         List<CourseTeacher> courseTeachers= courseTeacherService.queryCourseTeacherById(id,companyId);
        // 2、返回数据
        return courseTeachers;
    }
}
